<?php
/**
 * Form helpers
 *
 * @author den
 */
class Lemar_Form
{
	/**
	 * Returns error messages from Zend_Form validation in jguery inline validation plugin format
	 *
	 * @param Zend_Form $oForm
	 * @return array
	 */
	public static function getErrorMessages(Zend_Form $oForm)
	{
		$aErrorMessages = array();
		$aErrors = $oForm->getErrors();
		$aMessages = $oForm->getMessages();
		$iIndex = 0;
		foreach ($aErrors as $sControlName => $aErrorIndexes)
		{
			if (isset($aErrorIndexes[0]))
			{
				if ('wedding_type' == $sControlName) {
					// radio element has the same name but the different id
					// we use first id of radio group
					$aErrorMessages[$iIndex][] = '#indian_wedding';
				}
				else {
					$aErrorMessages[$iIndex][] = '#'.$sControlName;
				}
				$aErrorMessages[$iIndex][] = $aMessages[$sControlName][$aErrorIndexes[0]];
				$aErrorMessages[$iIndex][] = 'error';
				$iIndex++;
			}
		}
		return $aErrorMessages;
	}
}